﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataExtractionLanguage
{
    [Serializable]
    public class Function
    {
        public TokenTypeEnum FunctionType { get; set; }

        public ExpressionTerm StartIndexExp { get; set; }
        public ExpressionTerm LengthExp { get; set; }
        public ExpressionTerm StringExp { get; set; }

        public Function NextFunction { get; set; }

        public override string ToString()
        {
            string retVal = string.Empty;

            switch (FunctionType)
            {
                case TokenTypeEnum.SubString:
                    if (LengthExp != null)
                        retVal += string.Format(".{0}({1}, {2})", FunctionType, StartIndexExp, LengthExp);
                    else
                        retVal += string.Format(".{0}({1})", FunctionType, StartIndexExp);
                    break;

                case TokenTypeEnum.Length:
                    retVal += string.Format(".{0}", FunctionType);
                    break;

                case TokenTypeEnum.Like:
                    retVal += string.Format(".{0}({1})", FunctionType, StringExp);
                    break;
            }

            if (NextFunction != null)
                retVal += NextFunction.ToString();

            return retVal;
        }
    }
}
